﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.huigo.Framework.ServiceUtils;

namespace com.huigo.B2B.Web.pay
{
    public partial class PayResult : System.Web.UI.Page
    {
        /// <summary>
        /// 支付信息
        /// </summary>
        public PayInfo payInfo
        {
            get
            {
                if (Context.Handler is ITransfer)
                {
                    ITransfer trans = (ITransfer)Context.Handler;
                    return trans.TransPayInfo;
                }
                else return null;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //插入交易前信息
            if (PayService.Invoke(payInfo))
            {
                List<RequestFuncParams> list = new List<RequestFuncParams>();
                list.Add(new RequestFuncParams("orderId", payInfo.OrderId));
                list.Add(new RequestFuncParams("oId", payInfo.PayId.ToString()));
                list.Add(new RequestFuncParams("fee", payInfo.TotalFee.ToString()));
                BaseService service = new BaseService();
                ParserXml parser = service.RequestEntryService(Dict.ERequestFunc.BALANCE_PAY, list);
                if (parser != null && parser.RowsCount > 0 && parser["returnargs", 0] == "true")
                {
                    ShowMsg(true);
                }
                else
                {
                    ShowMsg(false);
                }
            }
            else
            {
                ShowMsg(false);
            }
        }

        private void ShowMsg(bool isSuc)
        {
            string strMsg = "<h1><span style=\"color: Red;\">" + payInfo.OrderName + "</span>支付成功!</h1>";
            if (!isSuc)
                strMsg = "<h1>支付失败!</h1>";
            msg.Text = strMsg;
        }

    }
}
